#include "BlackKnight.h"
#include "AIManager.h"
#include "BlackKnightAI.h"
#include "SGD Wrappers\CSGD_XAudio2.h"
#include "GamePlayState.h"

BlackKnight::BlackKnight(bool isPlayer)
{
	SetHP(60);
	SetMaxHP(60);
	SetMP(0);
	SetMaxMP(0);
	SetAtk(10);
	SetDef(6);
	SetSpd(4);
	SetAgi(4);
	SetSta(10);
	SetMov(3);
	SetRng(1);
	SetWpn(12);
	SetWpnName("Foam Greatsword");
	SetArm(10);
	SetArmName("Blackish Armor");
	SetPlayer(isPlayer);
	SetMoved(false);
	SetActed(false);
	type = BLACKKNIGHT;
	AniMan = AnimationManager::GetInstance();
	ChangeState(BKNIGHT_IDLE + GetFacing());
	this->currentTile = NULL;

	if(!this->IsPlayer())
	{
		this->currAI = new BlackKnightAI();
		currAI->SetCharIndex(AIManager::GetInstance()->GetAIChars()->size());
		AIManager::GetInstance()->GetAIChars()->push_back(this);
	}
	else
	{
		this->currAI = nullptr;
	}

	half = false;
	quarter = false;
	stop1 = false;
	stop2 = false;
	stop3 = false;
}


BlackKnight::~BlackKnight(void)
{
	if(this->currAI != nullptr)
		delete this->currAI;
}

void BlackKnight::Update(float elapsedTime)
{
	AniMan->Update(this, elapsedTime);
	if(GetHP() <= 0 && !this->IsDead())
	{
		dying = true;
		SetDead(true);
		if(!stop3)
		{
			CSGD_XAudio2::GetInstance()->SFXPlaySound(GamePlayState::GetInstance()->GetDrawID());
			stop3 = true;
		}
		SetHP(0);
	}

	if(dying)
	{
		ChangeState(BKNIGHT_DEATH);
		dying = false;
	}

	if(GetHP() <= GetMaxHP()/2 && !stop1)
		half = true;

	if(half)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(GamePlayState::GetInstance()->GetImID());
		half = false;
		stop1 = true;
	}

	if(GetHP() <= (GetMaxHP() - GetMaxHP()/4) && !stop2)
		quarter = true;

	if(quarter)
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(GamePlayState::GetInstance()->GetWoundID());
		quarter = false;
		stop2 = true;
	}
}
void BlackKnight::Render()
{
	AniMan->Render(this);
}